package hczc.longcai.com.hccrowdfunding.home.second_invest.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

import hczc.longcai.com.hccrowdfunding.R;
import hczc.longcai.com.hccrowdfunding.application.BaseApplication;
import hczc.longcai.com.hccrowdfunding.home.second_invest.beans.InvestClassify;

/**
 * Created by Administrator on 2016/1/12.
 */
public class InvestClassifyAdapter extends BaseAdapter {

    private static final String TAG = "InvestClassifyAdapter";
    private List<InvestClassify> investClassifies;
    private Context context;
//    private Bitmap bitmap;

    public InvestClassifyAdapter() {
    }

    public InvestClassifyAdapter(List<InvestClassify> investClassifies, Context context) {
        this.investClassifies = investClassifies;
        this.context = context;
    }

    @Override
    public int getCount() {
        return investClassifies.size();
    }

    @Override
    public Object getItem(int i) {
        return investClassifies.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder holder = null;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_invest_classify, null);
            BaseApplication.scaleScreenHelper.loadView(((ViewGroup) view));
            holder.textView = ((TextView) view.findViewById(R.id.invest_classify_listview_item_text));
            holder.imageView = ((ImageView) view.findViewById(R.id.invest_classify_listview_item_pic));
            holder.relativeLayout = ((RelativeLayout) view.findViewById(R.id.invest_classify_listview_relativelayout));
            holder.tab = ((ImageView) view.findViewById(R.id.invest_classify_listview_item_tab));
            holder.fengexian = view.findViewById(R.id.invest_classify_listview_item_fengexian);
            holder.bianjie = view.findViewById(R.id.invest_classify_listview_item_bianjie);
            view.setTag(holder);
        }

        InvestClassify investClassify = investClassifies.get(i);


        holder = ((ViewHolder) view.getTag());
        if (investClassify.getTab() == 0) {
//            Log.d(TAG,"*************************************");
            holder.tab.setVisibility(View.GONE);
        } else {
            holder.tab.setImageResource(investClassify.getTab());
        }

//        Log.d(TAG,"classifies："+classifies[i]);
        holder.textView.setText(investClassify.getClassify());
//        if(bitmap == null) {
//            bitmap = BitmapUtils.getCompBitmap(context.getResources(), R.drawable.u90, 50, 50);
//        }
//        holder.imageView.setImageBitmap(bitmap);
        if (investClassify.isSelect()) {
            holder.imageView.setVisibility(View.VISIBLE);
        } else
            holder.imageView.setVisibility(View.GONE);

        if (i == (getCount() - 1)) {
            holder.fengexian.setVisibility(View.GONE);
            holder.bianjie.setVisibility(View.VISIBLE);
        }


        return view;
    }


    class ViewHolder {
        TextView textView;
        ImageView imageView, tab;
        RelativeLayout relativeLayout;
        View fengexian, bianjie;

    }
}
